package service

import (
	"vtrip/internal/model"
	"vtrip/pkg/app"
)

type GetAllCommentRequest struct {
	ArticleId int `form:"article_id" binding:"required"`
	Page      int `form:"page,default=0"`
	PageSize  int `form:"page_size,default=0"`
}

type GetCommentReplyRequest struct {
	CommentId int `form:"comment_id" binding:"required"`
}

type MakeCommentRequest struct {
	ArticleId int    `form:"article_id" binding:"required"`
	Content   string `form:"content" binding:"required"`
}

type ReplyCommentRequest struct {
	CommentId int    `form:"comment_id" binding:"required"`
	Content   string `form:"content" binding:"required"`
}

type LikeCommentRequest struct {
	CommentId int `form:"comment_id" binding:"required"`
}

type DislikeCommentRequest struct {
	CommentId int `form:"comment_id" binding:"required"`
}

func (svc Service) GetAllComments(param *GetAllCommentRequest) ([]*model.CommentPart, error) {
	return svc.dao.FindAllComments(param.ArticleId,
		app.GetPageOffset(param.Page, param.PageSize), param.PageSize)
}

func (svc Service) MakeArticle(userId int, param *MakeCommentRequest) error {
	return svc.dao.CreateComment(userId, param.ArticleId, param.Content)
}

func (svc Service) GetCommentReply(param *GetCommentReplyRequest) ([]*model.CommentPart, error) {
	return svc.dao.GetCommentReply(param.CommentId)
}
